#include <iostream>

using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

void traverse(TreeNode* root, int* ans, int& cur){
    if(root == nullptr) return;
    traverse(root->left, ans, cur);
    ans[cur++] = root->val;
    traverse(root->right, ans, cur);
}

int kthSmallest(TreeNode* root, int k) {
    int ans[10005] = {};
    int cur = 0;
    traverse(root, ans, cur);
    return ans[k-1];
}